#include <i386/tss.h>
#include <i386/memory.h>
#include <i386/segment.h>
#include <i386/registers.h>
#include <string.h>

/* tss对象 */
static tss_t tss;

tss_t *get_tss()
{
	return &tss;
}

void update_tss_esp0(unsigned long stack)
{
	// 更新tss.esp0的值为任务的内核栈顶
	tss.esp0 = (unsigned int)stack;
}

void init_tss()
{
	memset(&tss, 0, sizeof(tss));
	// 内核的内核栈
	tss.esp0 = KERNEL_STATCK_TOP;
	// 内核栈选择子
	tss.ss0 = KERNEL_DATA_SEL;
    
	tss.iobase = sizeof(tss);

    // tss 段
	install_segment_descriptor(INDEX_TSS, sizeof(tss_t) - 1, (uint32_t )&tss, DA_386TSS);
    
	// 加载tss register
	load_tr(KERNEL_TSS_SEL);
}
